import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import componentsRouter from "./modules/components";
import otherRouter from "./modules/other";
import Layout from "@/layout/index";

/** 路由继承类型 */
export interface extendRoute {
  hidden?: boolean;
}

/**
 * 公共路由
 * @param { Boolean } keepAlive 是否需要缓存， 功能待开发
 * @param { Boolean } requireAuth 是否需要登录, 功能待开发
 */
export const constantRoutes: Array<RouteRecordRaw & extendRoute> = [
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "登录",
    },
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/",
    name: "layout",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "/home",
        component: () => import("@/views/home/index"),
        name: "Home",
        meta: { title: "首页", keepAlive: true, requireAuth: true },
      },
    ],
  },
];

// 异步组件
export const asyncRoutes = [
  componentsRouter,
  otherRouter,
  // {
  //   path: "/:pathMatch(.*)",
  //   redirect: "/error/404",
  // },
];

const router = createRouter({
  history: createWebHashHistory(), // hash
  routes: constantRoutes,
});

export default router;
